import { Effect, ImmerReducer } from "@/.umi/plugin-dva/connect"
import { getAdminL,getUser } from "@/service/people"
export interface IListp{
    checkedKeys: []
    adminname: string,
    password: string,
    role: number,
    adminid: string
}
export interface IListUser{
    userid: string
    username: string,
    password: string,
    tel: number,
    telcode: number,
    email: string,
    nickname: number,
    qq: string,
    wx: string,
    avatar: string
    sex: number,
    birthday:string

}
export interface IPeople{
    namespace: 'people',
    state:{
        adminList:Array<IListp>
        userList:Array<IListUser>
    },
    effects:{
        getAdminList: Effect,
        getuserList: Effect
    },
    reducers:{
        UPDATA_ADMIN: ImmerReducer
        UPDATA_USER: ImmerReducer

    }
}
const GetPeopleList:IPeople = {
    namespace: 'people',
    state: {
        adminList: [],
        userList:[]
    },
    effects:{
        *getAdminList({payload},{call,put}){
            const res = yield call(getAdminL,payload)
            yield put({
                type: 'UPDATA_ADMIN',
                payload:res.data
            })
        },
        *getuserList({payload},{call,put}){
            const res = yield call(getUser,payload)
            yield put({
                type: 'UPDATA_USER',
                payload:res.data
            })
        }
    },
    reducers:{
        UPDATA_USER(state,action){
            state.userList = action.payload
            // console.log(state.adminList,123);
        },
        UPDATA_ADMIN(state,action){
            state.adminList = action.payload
            // console.log(state.adminList,123);
        }
    }
}

export default GetPeopleList